home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / wtek0693.zip / OOPALLEY.ZIP / POINT.H < prev    next >
C/C++ Source or Header  |  1993-04-27  |  3KB  |  74 lines

  1. #ifndef POINT_H
  2. #define POINT_H
  3.  
  4. #include "object.h"
  5. #include <math.h>
  6.  
  7. extern const Class class_Point;
  8.  
  9. ////////////////////////////////////////////////////////////
  10. // class Point
  11. ////////////////////////////////////////////////////////////
  12. class Point : public Object
  13. {
  14.     short xc,yc;
  15. public:
  16.             // constructors, destructors
  17.             Point(short newx =0, short newy =0) { xc=newx; yc=newy; }
  18.             Point(const Point& p)               { xc = p.xc; yc = p.yc; }
  19.  
  20.             // operators
  21.     Point   operator+(Point p)  const
  22.                                         { return Point(xc+p.xc, yc+p.yc); }
  23.     Point   operator-()         const   { return Point(-xc,-yc); }
  24.     Point   operator-(Point p)  const   { return Point(xc-p.xc, yc-p.yc); }
  25.  
  26.     friend 
  27.     Point   operator*(Point p, int i)   { return Point(i*p.xc, i*p.yc); }
  28.     friend 
  29.     Point   operator*(int i, Point p)   { return Point(i*p.xc, i*p.yc); }
  30.     int     operator*(Point p)  const   { return xc*p.xc + yc*p.yc; }
  31.     bool    operator==(Point p) const   { return (xc==p.xc && yc==p.yc); }
  32.     bool    operator!=(Point p) const   { return (xc!=p.xc || yc!=p.yc); }
  33.     bool    operator<(Point p)  const   { return (yc<p.yc && xc<p.xc); }
  34.     bool    operator<=(Point p) const   { return (yc<=p.yc && xc<=p.xc); }
  35.     bool    operator>(Point p)  const   { return (yc>p.yc && xc>p.xc); }
  36.     bool    operator>=(Point p) const   { return (yc>=p.yc && xc>=p.xc); }
  37.     void    operator+=(Point p)         { xc += p.xc; yc += p.yc; }
  38.     Point   operator=(const Point& p)   {
  39.                                           xc = p.xc; yc = p.yc;
  40.                                           return *this;
  41.                                         }
  42.     void    operator-=(Point p)         { xc -= p.xc; yc -= p.yc; }
  43.     void    operator*=(int s)           { xc *= s; yc *= s; }
  44.                                                   
  45.  
  46.  
  47.             // member functions
  48.     short   x()                 const   { return xc; }
  49.     short   x(short newx)               { return xc = newx; }
  50.     short   y()                 const   { return yc; }
  51.     short   y(short newy)               { return yc = newy; }
  52.     double  dist(Point p)       const   { return hypot(xc-p.xc, yc-p.yc); }
  53.     Point   max(Point)          const;
  54.     Point   min(Point)          const;
  55.     Point   transpose()         const   { return Point(yc,xc); }
  56.     bool    isBelow(Point p)    const   { return yc > p.yc; }
  57.     bool    isAbove(Point p)    const   { return yc < p.yc; }
  58.     bool    isLeft(Point p)     const   { return xc < p.xc; }
  59.     bool    isRight(Point p)    const   { return xc > p.xc; }
  60.                                
  61.  
  62.     virtual bool            isEqual(const Object&)  const;
  63.     virtual const Class*    species()               const;
  64.     virtual const Class*    isA()                   const;
  65.     virtual void            printOn(ostream& strm)  const;
  66.     virtual int             compare(const Object&)  const;
  67.     virtual Object*         copy()                  const;
  68.     virtual void            deepenShallowCopy();
  69.     virtual unsigned        hash()                  const;
  70. };
  71.  
  72. #endif
  73.  
  74.